package com.winderinfo.yikaotianxia.ui.classification;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.winderinfo.yikaotianxia.R;
import com.winderinfo.yikaotianxia.ui.home.JiaoCaiBean;

import java.util.List;

public class BFaenAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private List<JiaoCaiBean.RowsBean> list;

    public BFaenAdapter(Context context, List<JiaoCaiBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_list_classtype, viewGroup, false);
        SelectedViewHolder selectedViewHolder = new SelectedViewHolder(view);
        return selectedViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        SelectedViewHolder selectedViewHolder = (SelectedViewHolder) viewHolder;

        selectedViewHolder.cl_title.setText(list.get(i).getTitle());
        selectedViewHolder.cl_price.setText("￥" + list.get(i).getPrice() + "元");
        selectedViewHolder.cl_sum.setText(list.get(i).getBuyNum() + " 人购买");
        Glide.with(context)
                .load(list.get(i).getPhoto())
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))//圆角半径
                .into(selectedViewHolder.cl_image);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class SelectedViewHolder extends RecyclerView.ViewHolder {

        private final TextView cl_type, cl_title, cl_jian, cl_price, cl_sum;
        private final ImageView cl_image;

        public SelectedViewHolder(@NonNull View itemView) {
            super(itemView);
            cl_image = itemView.findViewById(R.id.cl_image);
            cl_title = itemView.findViewById(R.id.cl_title);
            cl_type = itemView.findViewById(R.id.cl_type);
            cl_jian = itemView.findViewById(R.id.cl_jian);
            cl_price = itemView.findViewById(R.id.cl_price);
            cl_sum = itemView.findViewById(R.id.cl_sum);
        }
    }
}
